<?php

namespace common\models\datas;

use webback\models\data\Website;
use Yii;
use yii\helpers\ArrayHelper;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use common\components\behaviors\UpdateCacheBehavior;


class SendMsg extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%send_msg}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['type','wechat_id','reply_msg_id'], 'required'],
            [['type','text','event_type'], 'string'],
            [['wechat_id','reply_msg_id'], 'number'],
            [['event_type'],'required','when'=>function($model){
                return $model->type=='event';
            }],
            [['text'],'required','when'=>function($model){
                return $model->type=='text';
            }],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', '自增id'),
            'type' => Yii::t('common', '消息类型'),
            'text' => Yii::t('common', '发送内容'),
            'event_type' => Yii::t('common', '事件类型'),
            'reply_msg_id' => Yii::t('common', '回复消息'),
            'wechat_id' => Yii::t('common', '关联微信id'),
        ];
    }

    public function getReplyMsg()
    {
        return $this->hasOne(ReplyMsg::className(), ['id' => 'reply_msg_id']);
    }
}